package com.hzhr.iot.user.dao.helper;

import com.hzhr.iot.core.constant.CommonOptions;
import com.hzhr.iot.user.dao.CompanyDao;
import com.hzhr.iot.user.entity.CompanyEntity;
import com.hzhr.iot.user.queryModel.custom.CompanyCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class CompanyDaoHelper {
    @Autowired
    CompanyDao companyDao;

    public CompanyEntity getByCreateUserId(int createUserId) {
        CompanyCustomQueryModel queryModel = new CompanyCustomQueryModel();
        queryModel.setEqual_createUserId(createUserId);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        queryModel.setShow(true);
        CompanyEntity companyEntity = companyDao.selectEntity(queryModel);
        return companyEntity;
    }

    public CompanyEntity getById(int id) {
        CompanyCustomQueryModel queryModel = new CompanyCustomQueryModel();
        queryModel.setEqual_id(id);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        queryModel.setShow(true);
        CompanyEntity companyEntity = companyDao.selectEntity(queryModel);
        return companyEntity;
    }

    public CompanyEntity getByName(String name) {
        if (name == null) return null;
        CompanyCustomQueryModel queryModel = new CompanyCustomQueryModel();
        queryModel.setEqual_name(name);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        queryModel.setShow(true);
        CompanyEntity companyEntity = companyDao.selectEntity(queryModel);
        return companyEntity;
    }

    public int getCountByName(String name) {
        if (name == null) return 0;
        CompanyCustomQueryModel queryModel = new CompanyCustomQueryModel();
        queryModel.setEqual_name(name);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        queryModel.setShow(true);
        int count = companyDao.selectCount(queryModel);
        return count;
    }
}
